package com.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;

@Controller
public class UploadController {
   @RequestMapping("/upload.do")
    public void uploadFile(@RequestParam("pic") MultipartFile pic, HttpServletResponse response) throws IOException {
        response.setCharacterEncoding("UTF-8");;
        String filename = pic.getOriginalFilename();
        System.out.println("文件名："+filename);
        File file = new File("D:/upload/"+filename);
        pic.transferTo(file);
        response.sendRedirect("上传文件/uploadFile.html");
   }
}
